package com.cryptape.cita_wallet.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alm.token.R;
import com.cryptape.cita_wallet.bean.MiningOrderIncomeItem;

import java.util.List;

/**
 * Created by dengming on 1/3/20.
 */

public class MinerIncomeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<MiningOrderIncomeItem> datas;
    private CloudMinerAdapter.OnItemClickListener onItemClickListener;

    public MinerIncomeAdapter(List<MiningOrderIncomeItem> datas){
        this.datas = datas;
    }

    public void setDatas(List<MiningOrderIncomeItem> datas){
        this.datas = datas;
    }

    public void setOnItemClickListener(CloudMinerAdapter.OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MinerIncomeAdapter.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_mining_income,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        holder.itemView.setTag(position);
        ViewHolder incomeHolder = ((ViewHolder)holder);
        MiningOrderIncomeItem bean = datas.get(position);
        incomeHolder.tv_income_type.setText(bean.getTypeName()+"("+bean.getOrderLevelName()+")");
        incomeHolder.tv_income_time.setText(bean.getCreateTime());
        if(bean.getType() == 1) {
            incomeHolder.tv_income_amount.setText("+"+bean.getMoney());
            incomeHolder.iv_income_type.setBackgroundResource(R.drawable.icon_income);
        }else {
            incomeHolder.tv_income_amount.setText("-"+bean.getMoney());
            incomeHolder.iv_income_type.setBackgroundResource(R.drawable.icon_withdraw);

        }
//        ((ClountMinerViewHolder)holder).btn_buy.setTag(new Integer(position));
    }

    @Override
    public int getItemCount() {
        return datas == null?0:datas.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView iv_income_type;
        TextView tv_income_type;
        TextView tv_income_time;
        TextView tv_income_amount;

        public ViewHolder(View view) {
            super(view);
            tv_income_type = view.findViewById(R.id.tv_income_type);
            tv_income_time = view.findViewById(R.id.tv_income_time);
            tv_income_amount  = view.findViewById(R.id.tv_income_amount);
            iv_income_type  = view.findViewById(R.id.iv_income_type);
        }
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }
}
